package com.litchi.tutor.controller;

import cn.hutool.http.server.HttpServerRequest;
import com.litchi.tutor.common.base.ResponseVO;
import com.litchi.tutor.common.entity.Teacher;
import com.litchi.tutor.common.vo.TeacherResp;
import com.litchi.tutor.service.TeacherService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/teacher")
@Api("教师管理")
public class TeacherController {

    @Autowired
    TeacherService teacherService;

    @RequestMapping(value = "/resume", method = RequestMethod.POST)
    @ApiOperation("注册教师")
    public ResponseVO createTeacher(@RequestBody Teacher teacher, HttpServletRequest httpServletRequest) {
        teacherService.createTeacher(teacher, httpServletRequest);
        return ResponseVO.ok(null);
    }

    @RequestMapping(value = "/resume", method = RequestMethod.PUT)
    @ApiOperation("修改教师")
    public ResponseVO updateTeacher(@RequestBody Teacher teacher, HttpServletRequest httpServletRequest) {
        teacherService.updateTeacher(teacher, httpServletRequest);
        return ResponseVO.ok(null);
    }

    @RequestMapping(value = "/resumeByUserId", method = RequestMethod.GET)
    @ApiOperation("根据userId查询，如果有则，查没有查自己的")
    public ResponseVO getTeacherByUserId(@RequestParam(required = false) String userId, HttpServletRequest request) {
        TeacherResp teacherResp = teacherService.getTeacherByUserId(userId, request);
        return ResponseVO.ok(teacherResp);
    }

    @RequestMapping(value = "/resume", method = RequestMethod.GET)
    @ApiOperation("获取所有")
    public ResponseVO getTeacher(@RequestParam(required = false, defaultValue = "1") Long current,
                                 @RequestParam(required = false, defaultValue = "10") Long limit,
                                 @RequestParam(required = false) String birthplaces,
                                 @RequestParam(required = false) String teachingSubjectIds) {
        List<TeacherResp> list = teacherService.getTeacher(current, limit, birthplaces, teachingSubjectIds);
        return ResponseVO.ok(list);
    }
}
